package com.grz;

import com.grz.domain.User;
import com.grz.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;




@Slf4j
public class MapperProxyMain {
    public static void main(String[] args) throws IOException {
        // 1. 定义配置文件的位置
        String resource = "mybatis-config.xml";
        // 2. 获取这个文件的输入流
        InputStream inputStream = Resources.getResourceAsStream(resource);
        // 3. 基于配置文件构建SqlSessionFactory
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream,"dev");
        try (
                SqlSession sqlSession = sqlSessionFactory.openSession()
        ) {
            UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
            List<User> list = userMapper.selectUser();
            list.forEach(System.out::println);

            log.debug("debug级别的日志");
            log.info("info级别日志");
            log.error("出错拉....");
        }
    }
}
